package com.hulk.ratel.manage.commoncache;

import com.alicp.jetcache.anno.CacheType;
import com.alicp.jetcache.anno.Cached;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.hulk.ratel.common.constant.enums.YesOrNo;
import com.hulk.ratel.persistence.entity.TDictInfo;
import com.hulk.ratel.persistence.repository.TDictInfoRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Nonnull;


/**
 * Created by cmt on 2018/08/03.
 * 字典信息cache
 */
@Slf4j
@Component
public class DictInfoCache {

    @Autowired
    private TDictInfoRepository dictInfoRepository;

    //@Cacheable(value = "dictInfoCache", key = "#ruleCode+ 'DictInfoCache_findDictInfo'")
    @Cached(key = "#code + 'DictInfoCache_findDictInfo'", cacheType = CacheType.LOCAL ,localLimit = 4096, localExpire =600)
    public TDictInfo findDictInfo(String workId,@Nonnull String code) {
        TDictInfo diParam = new TDictInfo();
        diParam.setDictEn(code);
        diParam.setDictFlag(YesOrNo.YES.getValue());
        Wrapper<TDictInfo> queryDictInfo = new EntityWrapper<>(diParam);
        return dictInfoRepository.selectOne(queryDictInfo);
    }
}
